<template>
<div class="base-container">
  <div  class="btn-group-inline">
    <t-button @click="dialog.header='添加奖项';dialog.open_add_edit_award=true"  variant="outline" theme="primary">
      <t-icon name="add" slot="icon"/>
      添加奖项
    </t-button>
  </div>
  <t-table row-key="id" :columns="columns"
           :data="data" :selected-row-keys="selectedRowKeys" @select-change="(val)=>{selectedRowKeys=val}">
    <template #[`innovations.name`]="{row}">
      <t-link @click="dialog.objId=row.innovations.id;dialog.header=row.innovations.name;dialog.open_innovation_detail=true" hover="color"
              theme="primary">{{ row.innovations.name }}
      </t-link>
    </template>
    <template #awardsLevel="{row}">
      {{row.awardsLevel | filterByDict(dict.type.wcx_awards_level)}}
    </template>
    <template #awardsAmount="{row}">
      {{row.awardsAmount}}万元
    </template>
    <template #[`innovations.applicationField`]="{row}">
      {{ row.innovations.applicationField | filterByDict(dict.type.application_field) }}
    </template>
    <template #[`innovations.innovationCategory`]="{row}">
      {{ row.innovations.innovationCategory | filterByDict(dict.type.innovation_category) }}
    </template>
    <template #[`innovations.innovationStatus`]="{row}">
      <t-tag  @click="dialog.header='审批记录';dialog.objId=row.innovations.id;dialog.open_approve_list=true" class="cursor-pointer" :theme="handleTheme(row.innovations.innovationStatus, dict.type.innovation_status)" variant="light">
        {{ row.innovations.innovationStatus | filterByDict(dict.type.innovation_status) }}
      </t-tag>
    </template>
    <template #op="{row}">
      <t-button @click="dialog.header=row.innovations.name;dialog.objId=row.innovations.id;dialog.editOpen=false;dialog.open_detail=true"  size="small" variant="text" class="t-button-link">
        <t-icon name="info-circle" slot="icon"/>
        推荐详情
      </t-button>
      <t-button  theme="danger" @click="handleDelete(row)" size="small" variant="text"
                class="t-button-link">
        <t-icon name="delete" slot="icon" />
        删除
      </t-button>
    </template>
  </t-table>
  <add-edit-innovation-award @reload="getList" :header="dialog.header"   :objId="objId" :visible.sync="dialog.open_add_edit_award" v-if="dialog.open_add_edit_award"></add-edit-innovation-award>
  <innovation-detail-dialog :header="dialog.header" :objId="dialog.objId" :visible.sync="dialog.open_innovation_detail" v-if="dialog.open_innovation_detail"></innovation-detail-dialog>
  <approve-list :header="dialog.header" :objId="dialog.objId" :visible.sync="dialog.open_approve_list" v-if="dialog.open_approve_list"></approve-list>
  <recommend-detail-dialog :editOpen="dialog.editOpen" :header="dialog.header" :objId="dialog.objId" :visible.sync="dialog.open_detail" v-if="dialog.open_detail"></recommend-detail-dialog>

</div>
</template>

<script>
import innovationDetailDialog from "../innovation/components/innovation-detail-dialog.vue";
import approveList from "../approve/components/approve-list.vue";
import AddEditInnovationAward from "./components/add-edit-innovation-award.vue";
import RecommendDetailDialog from "../recommend/components/recommend-detail-dialog.vue";

export default {
  name: "innovation-award",
  dicts:['application_field','innovation_category', 'innovation_status', "wcx_awards_level"],
  components:{
    innovationDetailDialog,
    approveList,
    AddEditInnovationAward,
    RecommendDetailDialog
  },
  data(){
    return {
      objId: null,
      visible: true,
      dialog:{
        header:'',
        objId:0,
        open_add_edit_award: false,
        editOpen: false,
        open_detail: false,
        open_approve_list: false,
        open_innovation_detail: false,
      },
      selectedRowKeys:[],
      data:[],
      columns:[
        {
          colKey: "innovations.name",
          title: "成果名称",
          align: "center",
          width: 220
        },
        {
          colKey: "awardsLevel",
          title: "获奖等级",
          align: "center",
        },
        {
          colKey: "awardsAmount",
          title: "获奖金额",
          align: "center",
        },
        {
          colKey: "innovations.score",
          title: "评审平均分",
          align: "center",
          width: 120
        },
        {
          colKey: "innovations.applicationProject",
          title: "应用项目",
          align: "center",
          width: 180,
        },
        {
          colKey: "innovations.applicationField",
          title: "应用领域",
          align: "center",
        },
        {
          colKey: "innovations.innovationCategory",
          title: "创新类别",
          align: "center",
        },
        {
          colKey: "innovations.leaderName",
          title: "负责人",
          align: "center",
        },
        {
          colKey: "innovations.deptName",
          title: "工作单位",
          align: "center",
          width: 180,
        },
        {
          colKey: "innovations.innovationStatus",
          title: "成果状态",
          align: "center",
          width:120
        },
        {
          colKey: "createTime",
          title: "创建时间",
          align: "center",
          width: 200
        },
        {
          colKey: "op",
          title: "操作",
          align: "center",
          width: 130
        },
      ]
    }
  },
  created() {
    const objId = this.$route.params && this.$route.params.taskId;
    if (!objId) {
      this.$message.error("缺少业务id");
      return false;
    }
    this.objId = objId;
    this.getList();
  },
  methods:{
    getList(){
      this.$api.wcx.apply.innovationAwardsList({annualAwardsId:this.objId}).then(
        (res) => {
          this.data = res.data;
        }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    handleDelete(row){
      const confirmDia = this.$dialog.confirm({
        header:"系统提示",
        body:`是否确认删除成果为"${row.innovations.name}"的数据项？`,
        theme: "warning",
        onConfirm: ({ e }) => {
          this.$api.wcx.apply.innovationAwardsDel(row.id).then(
            (res) => {
              this.getList();
              this.$message.success("删除成功");
              // 请求成功后，销毁弹框
              confirmDia.destroy();
            }).catch((e) => {
            this.$message.error(e.toString());
          });
        },
      })
    },
    closeDialog() {
      this.$emit("update:visible", false);
    },
  }
}
</script>

<style scoped>

</style>
